from soj.builtin.compare.common import CompareResult,CompareType,ensure_file
from soj.builtin.compare.float.float import FloatCompare,DEFAULT_PRECISION
from soj.builtin.compare.fulltext.fulltext import FullTextCompare
from soj.builtin.compare.syscmd.syscmd import SyscmdCompare
from soj.builtin.compare.token.token import TokenCompare
from pathlib import Path
class CompareOrchestrator:
    def __init__(self,type:CompareType,file_p:Path,file_j:Path,
                 precision_limit:int=DEFAULT_PRECISION):
        ensure_file(file_p),ensure_file(file_j)
        self.file_p=file_p
        self.file_j=file_j
        self.type=type
        if type==CompareType.FLOAT:
            self.prec=precision_limit
    def compare(self)->CompareResult:
        ensure_file(self.file_j),ensure_file(self.file_p)
        if self.type==CompareType.FLOAT:
            cp=FloatCompare(self.file_p,self.file_j,self.prec)
            return cp.compare()
        elif self.type==CompareType.FULLTEXT:
            cp=FullTextCompare(self.file_p,self.file_j)
            return cp.compare()
        elif self.type==CompareType.TOKEN:
            cp=TokenCompare(self.file_p,self.file_j)
            return cp.compare()
        elif self.type==CompareType.SYSCMD:
            cp=SyscmdCompare(self.file_p,self.file_j)
            return cp.compare()
        else:
            raise ValueError("Unknown compare type")
